package com.springboot.blog.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.springboot.blog.beans.Blog;
import com.springboot.blog.beans.Rps;
import com.springboot.blog.beans.Urs;
import com.springboot.blog.config.utils.R;
import com.springboot.blog.dao.RpsdDao;
import com.springboot.blog.dao.UrsDao;
import com.springboot.blog.service.PermissionService;
import com.springboot.blog.service.RolesService;
import net.sf.json.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/role")
public class PermissionController {

    @Resource
    private RpsdDao rpsdDao;
    @Resource
    private UrsDao ursDao;

    @RequestMapping("AllRole")
    public R AllRole(String rolep,String limits){
        List list = JSONArray.toList(JSONArray.fromObject(limits));
        for (Object s : list){
            System.out.println(s);
        }
        Rps rps = new Rps();
        for (int i=0;i<list.size();i++){
            rps.setPid(Integer.parseInt(list.get(i).toString()));
            rps.setRid(Integer.parseInt(rolep));
            rpsdDao.insert(rps);
        }
        if (2 >0){
            return R.ok();
        }
        return R.error();
    }

    @RequestMapping("addRoleUser")
    public R addRoleUser(String roleUsername,String rolejuese){
        Urs urs = new Urs();
        urs.setUid(Integer.parseInt(roleUsername));
        urs.setRid(Integer.parseInt(rolejuese));
        int insert = ursDao.insert(urs);
        if (insert>0){
            return R.ok();
        }
        return R.error();
    }
}
